﻿Imports DevExpress.Web

Public Class AdminConfirmReturn
    Inherits System.Web.UI.Page
    Dim mt As New MuonTra_BLL()
    Dim p As New MuonTra_DTO()
    Dim pageControl As ASPxPageControl
    Dim dt As DataTable
    Dim cls As New ConnectDB()
    Dim ds As DataSet = Nothing
    Dim objUser As New LoginHelper("", "")
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        loadThongTinTra()
        loadThongTinDocGiaTra()
        themControl()
    End Sub

    Public Sub loadThongTinTra()
        p._idsach = Request.QueryString("id_sach")
        p._taikhoan = Request.QueryString("taikhoan")
        p._ngaytra = DateTime.ParseExact(Request.QueryString("ngaytra"), "dd/MM/yyyy", Nothing)
        grid_return.DataSource = mt.loadThongTinTraPopup(p)
        grid_return.DataBind()
    End Sub
    Public Sub loadThongTinDocGiaTra()
        p._taikhoan = Request.QueryString("taikhoan")
        datalist_docgia.DataSource = mt.loadInfoDocGiaMuon(p)
        datalist_docgia.DataBind()
    End Sub

    Protected Sub grid_return_CustomColumnDisplayText(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs) Handles grid_return.CustomColumnDisplayText
        If e.Column.VisibleIndex = 5 Then
            Dim songayquahan As String = DateDiff(DateInterval.Day, Convert.ToDateTime(e.GetFieldValue("ngaytra").ToString()), DateTime.ParseExact(Request.QueryString("ngaytra"), "dd/MM/yyyy", Nothing))
            If songayquahan > 0 Then
                e.Column.CellStyle.ForeColor = Drawing.Color.Red
                e.Column.CellStyle.Font.Bold = True
                e.DisplayText = songayquahan
            Else
                e.DisplayText = "0"
            End If
        End If
    End Sub

    Protected Sub btn_dongy_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_dongy.Click
        themTra()
    End Sub

    Public Sub themTra()
        Dim dt As New DataTable()
        dt.Columns.Add("id_sach", GetType(String))
        dt.Columns.Add("taikhoan", GetType(String))
        dt.Columns.Add("tennv", GetType(String))
        dt.Columns.Add("ngaytra", GetType(DateTime))
        dt.Columns.Add("songayquahan", GetType(String))
        dt.Columns.Add("mucphat", GetType(String))
        dt.Columns.Add("ghichu", GetType(String))
        For i As Integer = 0 To grid_return.VisibleRowCount - 1
            Dim dr As DataRow = grid_return.GetDataRow(i)
            Dim id_sach As String = dr("id_sach").ToString()
            Dim taikhoan As String = dr("taikhoan").ToString()
            Dim tennv As String = lb_nv.Text
            Dim ngaytra As String = dr("ngaytra").ToString()
            Dim songayquahan As String = DateDiff(DateInterval.Day, Convert.ToDateTime(ngaytra), DateTime.ParseExact(Request.QueryString("ngaytra"), "dd/MM/yyyy", Nothing))
            If songayquahan < 0 Then
                songayquahan = 0
            End If
            dt.Rows.Add(taikhoan, tennv, id_sach, ngaytra, songayquahan)
        Next
        For j As Integer = 0 To dt.Rows.Count - 1
            Dim dr As DataRow = dt.Rows(j)
            dr("mucphat") = TryCast(panelMP.FindControl("txt" + j.ToString()), ASPxTextBox).Text.ToString()
            dr("ghichu") = TryCast(panelMP.FindControl("mmtxt" + j.ToString()), ASPxMemo).Text.ToString()
        Next
        mt.themTra(dt)
        ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Trả Sách Thành Công - Tải Lại Trang');hidePopup();", True)
    End Sub
    Public Sub themControl()
        Dim sosach As String = Request.QueryString("sosach")
        For i As Integer = 0 To sosach - 1
            Dim divMaSach As HtmlGenericControl = New HtmlGenericControl("div")
            Dim spanMS As HtmlGenericControl = New HtmlGenericControl("span")
            Dim lb As ASPxLabel = New ASPxLabel()
            lb.ID = "lb" + i.ToString()
            Dim dr As DataRow = grid_return.GetDataRow(i)
            lb.Text = dr("id_sach").ToString()
            spanMS.Attributes("class") = "label label-primary"
            spanMS.InnerText = "Mã Sách:"
            spanMS.Style.Add("font-size", "smaller")
            divMaSach.Attributes("class") = "form-group"
            divMaSach.Controls.Add(spanMS)
            divMaSach.Controls.Add(lb)

            Dim divTienPhat As HtmlGenericControl = New HtmlGenericControl("div")
            Dim spanTienPhat As HtmlGenericControl = New HtmlGenericControl("span")
            Dim txt As ASPxTextBox = New ASPxTextBox()
            txt.ID = "txt" + i.ToString()
            txt.Style.Add("margin-top", "5px")
            txt.Width = New Unit("50%")
            txt.MaskSettings.Mask = "<0..999g>.<000..999> VND"
            txt.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.All
            spanTienPhat.Attributes("class") = "label label-primary"
            spanTienPhat.Style.Add("font-size", "smaller")
            spanTienPhat.InnerText = "Mức Phạt:"
            divTienPhat.Attributes("class") = "form-group"
            divTienPhat.Controls.Add(spanTienPhat)
            divTienPhat.Controls.Add(txt)

            Dim divGhiChu As HtmlGenericControl = New HtmlGenericControl("div")
            Dim spanGhiChu As HtmlGenericControl = New HtmlGenericControl("span")
            Dim mmtxt As ASPxMemo = New ASPxMemo()
            mmtxt.ID = "mmtxt" + i.ToString()
            mmtxt.Width = "300"
            mmtxt.Height = "75"
            mmtxt.Style.Add("margin-top", "5px")
            spanGhiChu.Attributes("class") = "label label-primary"
            spanGhiChu.Style.Add("font-size", "smaller")
            spanGhiChu.InnerText = "Ghi Chú:"
            divGhiChu.Attributes("class") = "form-group"
            divGhiChu.Controls.Add(spanGhiChu)
            divGhiChu.Controls.Add(mmtxt)

            Dim tb As Table = New Table()
            tb.Width = New Unit("100%")
            Dim tr As TableRow = New TableRow()
            tb.Rows.Add(tr)
            tr.Style.Add("border-bottom", "3px solid gray")

            Dim tdMS As TableCell = New TableCell()
            tr.Cells.Add(tdMS)
            tdMS.CssClass = "col-lg-8"
            tdMS.Controls.Add(divMaSach)
            tdMS.Controls.Add(divTienPhat)

            Dim tdGC As TableCell = New TableCell()
            tr.Cells.Add(tdGC)
            tdGC.Style.Add("padding-top", "5px")
            tdGC.CssClass = "col-lg-8 col-sm-3"
            tdGC.Controls.Add(divGhiChu)

            panelMP.Controls.Add(tb)
        Next
    End Sub

    Protected Sub lb_nv_Init(ByVal sender As Object, ByVal e As EventArgs) Handles lb_nv.Init
        objUser = TryCast(Session("sesLoginAdmin"), LoginHelper)
        lb_nv.Text = objUser.UserName
    End Sub
End Class